﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace ExcelImport.Validators
{
    public class RequiredValidator : IDataRowProcessor
    {
        public void Run(DataRow row, PipelineContext context)
        {
            foreach (var importProperty in context.ImportTable.ImportProperties.Where(p => p.Ordinal.HasValue && p.IsRequired))
            {
                string value = row[importProperty.Ordinal.Value]?.ToString();

                if (string.IsNullOrEmpty(value))
                {
                    context.AddValidationResult(new ValidationResult($"第{context.Index}行,{importProperty.HeaderName}不能为空"));
                }
            }
        }
    }
}
